package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理玩家信息
func (xd *XdDriver) CheckXIYOUPlayerInfoData(info D.XIYOUPlayerInfo) {
	log.Infof("西游伏魔-当前妖力 %s 关卡 %d 道运等级 %d 完成时间 %s",
		D.GetCombatValueDesc(info.CombatValue), info.Passes, info.Level, info.UpdateTime.Format("2006-01-02 15:04:05"))
	if info.CombatValue > 0 {
		xd.UserData.XIYOUCombatValue = info.CombatValue
		xd.UserData.XIYOULevel = info.Level
		log.Infof("西游伏魔-当前妖力 %s", D.GetCombatValueDesc(info.CombatValue))
	}
	if info.Updating {
		timeNow := time.Now()
		if info.UpdateTime.Before(timeNow) {
			log.Infof("西游伏魔-道运升级完成")
			xd.ResetTaskByID(proto.S_XIYOU_PLAYER_BRESS_UPLEV)
		} else {

		}
	}
	if info.Passes > 0 && xd.UserData.Passes != info.Passes {
		xd.UserData.Passes = info.Passes
		target := info.Passes
		log.Infof("西游伏魔-准备通过关卡 %d", target)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_XIYOU_PLAYER_UPDATE_PROGRESS,
			fmt.Sprintf("08 %s 10 %s", xd.UserData.Activity[D.Activity_XIYOU_PLAYER_BRESS].ID, info.PassesStr)))

		time.Sleep(5 * time.Second)
		xd.ResetTaskByID(proto.S_XIYOU_PLAYER_DATA_INFO)
	}
}
func (xd *XdDriver) CheckXIYOUSecretInfoData(info D.XIYOUSecretInfo) {
	if len(info.ID) == 1 {
		//log.Infof("西游伏魔-幻境第%d关 等待开始挑战BOSS", info.Level)
		//time.Sleep(20 * time.Second)
		log.Infof("西游伏魔-幻境第%d关 开始挑战BOSS", info.Level)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_XIYOU_SECRET_KILL,
			fmt.Sprintf("08 %s 10 %02X 18 01", xd.UserData.Activity[D.Activity_XIYOU_PLAYER_BRESS].ID, info.Level)))
	} else if len(info.ID) == 2 {
		a := proto.ParaIntDataByHexStr(info.ID[0]) % 100
		b := proto.ParaIntDataByHexStr(info.ID[0]) % 100
		c := a
		data := info.ID[0]
		if b < a {
			c = b
			data = info.ID[1]
		}
		//log.Infof("西游伏魔-幻境第%d关 等待继续战斗选择%d星", info.Level, c)
		//time.Sleep(20 * time.Second)
		log.Infof("西游伏魔-幻境第%d关 继续战斗选择%d星", info.Level, c)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_XIYOU_SECRET_SELECT,
			fmt.Sprintf("08 %s 10 %02X 18 01 20 %s", xd.UserData.Activity[D.Activity_XIYOU_PLAYER_BRESS].ID, info.Level, data)))
	} else {
		log.Infof("西游伏魔-幻境未知参数")
	}
}

func (xd *XdDriver) CheckXIYOUSecretKillInfoData(level int) {
	if level > 0 {
		log.Infof("西游伏魔-幻境第%d关完成，开始挑战%d关", level, level+1)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_XIYOU_SECRET_START,
			fmt.Sprintf("08 %s 10 %02X 18 01", xd.UserData.Activity[D.Activity_XIYOU_PLAYER_BRESS].ID, level+1)))
	}
}
